home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Add-Ons / 4D / ComboBox 1.1.1 / src / ComboBox.c < prev    next >
C/C++ Source or Header  |  1996-02-23  |  24KB  |  714 lines

  1. //---------------------------------------------------------------------------------------
  2. //
  3. //    ComboBox.c -- Source for ComboBox external area
  4. //
  5. //    Copyright ©1995-1996, Pensacola Christian College
  6. //
  7. //    ======================================================================
  8. //    Change History
  9. //    ======================================================================
  10. //
  11. //    1.0            08/  /95        Steve Dwire
  12. //                                            Initial release
  13. //
  14. //    1.0.1        10/18/95        Steve Dwire
  15. //                                            Fixed problem with unlocked PackData handle in LaunchListProcess()
  16. //                                            Default PICT resource IDs changed to reflect new PICTs
  17. //
  18. //    1.1            11/28/95        Steve Dwire
  19. //                                            Added handler for kCB_GetFontNum
  20. //
  21. //                    11/28/95        Steve Dwire
  22. //                                            Added AreaStruct() function to draw area in layout editor.
  23. //
  24. //    1.1.1a2    02/23/96        Steve Dwire
  25. //                                            Fix dumb mistake in AreaStruct() that caused some text fields
  26. //                                            to be displayed incorrectly.
  27. //
  28. //---------------------------------------------------------------------------------------
  29.  
  30. #include <Ext4D.h>
  31. #include <Palettes.h>
  32. #include "ComboBoxMain.h" // Include your header here.
  33. #if defined(powerc) || WINVER
  34. #include "ComboBoxList.h"
  35. #endif
  36.  
  37. //---------------------------------------------------------------------------------
  38. //
  39. // FUNCTION: {Main/FourDPack/main}
  40. //
  41. //---------------------------------------------------------------------------------
  42. //The main entry point
  43. //This the main entry point of the package.
  44. #if defined(powerc)
  45. pascal void Main(SLONG entryPoint, PackagePtr params, PackHnd *PackData, ResultPtr result){
  46. #else
  47. #if WINVER
  48. void pascal FourDPack(SLONG entryPoint, PackagePtr params, PackHnd *PackData, ResultPtr result){
  49. #else
  50. pascal void main(SLONG entryPoint, PackagePtr params, PackHnd *PackData, ResultPtr result){
  51. #endif
  52. #endif
  53.     OSErr err;
  54.  
  55.     //Do we have a package data handle?
  56.     if(*PackData) 
  57.         switch(entryPoint)
  58.         {
  59.             case kDeinitPackage:
  60.                 // Dispose any memory taken by members of package data block.
  61.                 DisposeHandle((Handle)*PackData);
  62.                 break;
  63.             //For each item in the STR# there is an entry in the package entrypoint.
  64.             //The entrypoints and their parameters are handled regarding the contents of the main STR#.
  65.             case k_MyAreaProc:
  66.                 switch(((EventRecord*)(params[0]))->what)
  67.                 {
  68.                     //•Remove or comment the next three lines if you want to handle kIdleEvt in your area
  69.                     //case kIdleEvt:
  70.                     //    err = noErr;
  71.                     //    break;
  72.                     case kInitEvt:
  73.                         err = InitAreaData((AreaHnd*)params[3],*PackData,(Rect*)params[1],(EventRecord*)(params[0]));
  74.                         break;
  75.                     case kDeInitEvt:
  76.                         // Dispose any memory taken by members of area’s data block.
  77.                         if((**PackData)->CurrAreaHnd == *(AreaHnd*)params[3])
  78.                             (**PackData)->CurrAreaHnd = NULL;
  79.                         DeInitAreaData(*((AreaHnd*)params[3]));
  80.                         DisposeHandle(*((Handle*)params[3]));
  81.                         //•If cannot DeInit, uncomment next two lines.
  82.                         //if(event->message == kCanRefuse)
  83.                         //  event->message = kZoneRefuseDeInit;
  84.                         break;
  85.                     case kStructEvt:
  86.                         (**((AreaHnd*)params[3]))->MyLytType = kDesign;
  87.                         //•Draw the area image on the layout design window
  88.                         //v1.1
  89.                         // added the following line:
  90.                         AreaStruct((UBYTE*)params[2], (Rect*)params[1], *PackData);
  91.                         // to draw the area in the layout editor.  It must go here rather than in ComboBoxArea.c,
  92.                         // because I want to use the default settings the programmer has set (Using CB_SetDefXxx).
  93.                         // In order to do that, I must have a handle to the Package Data.  I can't get it from
  94.                         // the design environment using GetPackDataHnd() because no variables are defined in the
  95.                         // design environment, therefore, I can't read CB_PackData.  I must have the Package Data
  96.                         // Handle passed in directly, as it is here.
  97.                         ((EventRecord*)(params[0]))->message = kZoneIsCustomized;
  98.                         break;
  99.                     default:
  100.                         err = Area((EventRecord*)params[0],
  101.                                                 (Rect*)params[1],
  102.                                                 (UBYTE*)params[2],
  103.                                                 (AreaHnd*)params[3]);
  104.                 }//•Include one case for each routine in your package.
  105.                 break;
  106.             case kCB_SetDefTxtFnt:
  107.                 CB_SetDefTxtFnt(*PackData,*(SWORD*)params[0],*(SWORD*)params[1],*(SWORD*)params[2]);
  108.                 break;
  109.             case kCB_SetDefTxtCol:
  110.                 CB_SetDefTxtCol(*PackData,*(SWORD*)params[0],*(SWORD*)params[1]);
  111.                 break;
  112.             case kCB_SetDefLstFnt:
  113.                 CB_SetDefLstFnt(*PackData,*(SWORD*)params[0],*(SWORD*)params[1],*(SWORD*)params[2]);
  114.                 break;
  115.             case kCB_SetDefLstCol:
  116.                 CB_SetDefLstCol(*PackData,*(SWORD*)params[0],*(SWORD*)params[1]);
  117.                 break;
  118.             case kCB_SetDefLstRws:
  119.                 CB_SetDefLstRws(*PackData,*(SWORD*)params[0]);
  120.                 break;
  121.             case kCB_SetDefPopPic:
  122.                 CB_SetDefPopPic(*PackData,*(SWORD*)params[0],*(SWORD*)params[1],*(SWORD*)params[2],
  123.                                                                     *(SWORD*)params[3],*(SWORD*)params[4],*(SWORD*)params[5]);
  124.                 break;
  125.             case kCB_SetDefGap:
  126.                 CB_SetDefGap(*PackData,*(SWORD*)params[0],*(SWORD*)params[1],
  127.                                                              *(SWORD*)params[2],*(SWORD*)params[3]);
  128.                 break;
  129.             case kCB_SetDefLead:
  130.                 CB_SetDefLead(*PackData,*(SWORD*)params[0]);
  131.                 break;
  132.             case kCB_SetDefFlags:
  133.                 CB_SetDefFlags(*PackData,*(SWORD*)params[0],*(SWORD*)params[1],
  134.                                                                     *(SWORD*)params[2],*(SWORD*)params[3],
  135.                                                                     *(SWORD*)params[4],*(SWORD*)params[5]);
  136.                 break;
  137.             case kCB_SetTxtFnt:
  138.                 CB_SetTxtFnt(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2],
  139.                                                                                     *(SWORD*)params[3]);
  140.                 break;
  141.             case kCB_SetTxtCol:
  142.                 CB_SetTxtCol(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2]);
  143.                 break;
  144.             case kCB_SetLstFnt:
  145.                 CB_SetLstFnt(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2],
  146.                                                                                     *(SWORD*)params[3]);
  147.                 break;
  148.             case kCB_SetLstCol:
  149.                 CB_SetLstCol(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2]);
  150.                 break;
  151.             case kCB_SetLstRws:
  152.                 CB_SetLstRws(*(AreaHnd*)params[0],*(SWORD*)params[1]);
  153.                 break;
  154.             case kCB_GetLstRws:
  155.                 *((SLONG*)result) = CB_GetLstRws(*(AreaHnd*)params[0]);
  156.                 break;
  157.             case kCB_SetPopPic:
  158.                 CB_SetPopPic(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2],
  159.                                                                                     *(SWORD*)params[3],*(SWORD*)params[4],
  160.                                                                                     *(SWORD*)params[5],*(SWORD*)params[6]);
  161.                 break;
  162.             case kCB_SetGap:
  163.                 CB_SetGap(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2],
  164.                                                                              *(SWORD*)params[3],*(SWORD*)params[4]);
  165.                 break;
  166.             case kCB_SetLead:
  167.                 CB_SetLead(*(AreaHnd*)params[0],*(SWORD*)params[1]);
  168.                 break;
  169.             case kCB_SetFlags:
  170.                 CB_SetFlags(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2],
  171.                                                                                 *(SWORD*)params[3],*(SWORD*)params[4],
  172.                                                                                 *(SWORD*)params[5],*(SWORD*)params[6]);
  173.                 break;
  174.             case kCB_FillLst:
  175.                 CB_FillLst(*(AreaHnd*)params[0],(UBYTE*)params[1]);
  176.                 break;
  177.             case kCB_UpdateLst:
  178.                 CB_UpdateLst(*(AreaHnd*)params[0]);
  179.                 break;
  180.             case kCB_SetLstPos:
  181.                 CB_SetLstPos(*(AreaHnd*)params[0],*(SWORD*)params[1]);
  182.                 break;
  183.             case kCB_GetLstPos:
  184.                 *((SLONG*)result) = CB_GetLstPos(*(AreaHnd*)params[0]);
  185.                 break;
  186.             case kCB_SetTxt:
  187.                 CB_SetTxt(*(AreaHnd*)params[0],(TextBlock*)params[1]);
  188.                 break;
  189.             case kCB_GetTxt:
  190.                 CB_GetTxt(*(AreaHnd*)params[0],(TextBlock*)params[1]);
  191.                 break;
  192.             case kCB_SetModified:
  193.                 CB_SetModified(*(AreaHnd*)params[0],*(SWORD*)params[1]);
  194.                 break;
  195.             case kCB_GetModified:
  196.                 *((SLONG*)result) = CB_GetModified(*(AreaHnd*)params[0]);
  197.                 break;
  198.             case kCB_SetEnabled:
  199.                 CB_SetEnabled(*(AreaHnd*)params[0],*(SWORD*)params[1]);
  200.                 break;
  201.             case kCB_GetEnabled:
  202.                 *((SLONG*)result) = CB_GetEnabled(*(AreaHnd*)params[0]);
  203.                 break;
  204.             case kCB_SetHilite:
  205.                 CB_SetHilite(*(AreaHnd*)params[0],*(SWORD*)params[1],*(SWORD*)params[2]);
  206.                 break;
  207.             case kCB_GetHilite:
  208.                 CB_GetHilite(*(AreaHnd*)params[0],(SWORD*)params[1],(SWORD*)params[2]);
  209.                 break;
  210.             //v1.1
  211.             // Added following lines:
  212.             case kCB_GetFontNum:
  213.                 *((SLONG*)result) = CB_GetFontNum((UBYTE*)params[0]);
  214.                 break;
  215.             // to handle CB_GetFontNum function
  216.         }
  217.     //If we don’t have a package data block we must create one
  218.     else 
  219.     {
  220.         switch(entryPoint)
  221.         {
  222.             case kInitPackage:
  223.                 // Let's create the package datas…
  224.                 *PackData = (PackHnd)NewHandleClear(sizeof(PackStr));
  225.                 InitExtension(params); //call standard initialization routine in ExtRoutines.c
  226.                 if (*PackData)
  227.                 {
  228.                     //•Allocate and initialize any memory needed by members of package data block.
  229.                     HLock((Handle)*PackData);
  230.                     InitPackageData(*PackData);
  231.                     LaunchListProcess(*PackData);
  232.                     HUnlock((Handle)*PackData);
  233.                 }
  234.                 break;
  235.         }
  236.     }
  237. }
  238.  
  239.  
  240. //---------------------------------------------------------------------------------
  241. //
  242. // FUNCTION: InitPackageData
  243. //
  244. //---------------------------------------------------------------------------------
  245.  
  246. void InitPackageData(PackHnd PackData)
  247. {
  248.     PackPtr                    PackDataPtr;
  249.     ParameterBlock    block;
  250.     ValuePtr                value;
  251.     
  252.     // Store the handle to our package data in interprocess variable ◊CB_PackData
  253.     // We do this so that our other process (the one that handles the list window)
  254.     // can look at the CurrAreaHnd element to know which area it's supposed to be 
  255.     // working on now.
  256.     
  257.     //For some reason, the compiler doesn't seem to like string literals, so I do
  258.     //it this slow way.
  259.     block.fName[0] = (SBYTE)11; // It's supposed to be a pascal string.
  260.     block.fName[1] = 'C';
  261.     block.fName[2] = 'B';
  262.     block.fName[3] = '_';
  263.     block.fName[4] = 'P';
  264.     block.fName[5] = 'a';
  265.     block.fName[6] = 'c';
  266.     block.fName[7] = 'k';
  267.     block.fName[8] = 'D';
  268.     block.fName[9] = 'a';
  269.     block.fName[10] = 't';
  270.     block.fName[11] = 'a';
  271.     block.fName[12] = '\0'; // just in case something looks at it C-Style.
  272.     
  273.     value = (ValuePtr) NewPtr(sizeof(ValueBlock));
  274.     value->fType = eLongint;
  275.     value->uValue.fLongint = (SLONG)PackData;
  276.     block.fH = (XHANDLE)value;
  277.     
  278.     CALL4D(kEX_SET_GLOBALVAR,&block);
  279.     DisposePtr((Ptr)value);
  280.     
  281.     // Now it's time to actually set up our initial defaults.
  282.     HLock((Handle)PackData);
  283.     PackDataPtr = *PackData;
  284.     
  285.     //v1.0.1  following lines changed to receive new PICT resources:
  286.     PackDataPtr->DefCPICTResUp                        = GetResID('4BNX','PICT',1);
  287.     PackDataPtr->DefCPICTResDn                        = GetResID('4BNX','PICT',2);
  288.     PackDataPtr->DefCPICTResDis                        = GetResID('4BNX','PICT',3);
  289.     PackDataPtr->DefMPICTResUp                        = GetResID('4BNX','PICT',4);
  290.     PackDataPtr->DefMPICTResDn                        = GetResID('4BNX','PICT',5);
  291.     PackDataPtr->DefMPICTResDis                        = GetResID('4BNX','PICT',6);
  292.     
  293.     PackDataPtr->DefTextFont                            = 1;
  294.     PackDataPtr->DefTextSize                            = 9;
  295.     PackDataPtr->DefTextStyle                            = 0;
  296.     PackDataPtr->DefTextFGColor                        = 15;
  297.     PackDataPtr->DefTextBGColor                        = 0;
  298.     PackDataPtr->DefListFont                            = 1;
  299.     PackDataPtr->DefListSize                            =    9;
  300.     PackDataPtr->DefListStyle                            = 0;
  301.     PackDataPtr->DefListFGColor                        = 15;
  302.     PackDataPtr->DefListBGColor                        = 0;
  303.     PackDataPtr->DefListRows                            = 5;
  304.     PackDataPtr->DefPixGap                                = 0;
  305.     PackDataPtr->DefTopGap                                = 3;
  306.     PackDataPtr->DefLeftGap                                = 0;
  307.     PackDataPtr->DefRightGap                            = 0;
  308.     PackDataPtr->DefPixLead                                = 0;
  309.     PackDataPtr->DefFlags.CanFind                    = true;
  310.     PackDataPtr->DefFlags.CanFill                    = true;
  311.     PackDataPtr->DefFlags.CanList                    = true;
  312.     PackDataPtr->DefFlags.CanEdit                    = true;
  313.      PackDataPtr->DefFlags.ListOnActivate    = true;
  314.      PackDataPtr->DefFlags.ListOnKeystroke    = true;
  315.      HUnlock((Handle)PackData);
  316. }
  317.  
  318.  
  319. //---------------------------------------------------------------------------------
  320. //
  321. // FUNCTION: AreaStruct
  322. //
  323. //---------------------------------------------------------------------------------
  324.  
  325. void AreaStruct(UBYTE *name, Rect *bounds, PackHnd PackDataHnd)
  326. {
  327.     PicHandle    ThePICT;
  328.     Rect            TextRect, PICTRect;
  329.     int                TopBorder, RightBorder;
  330.     FontInfo    FntInfo;
  331.     GrafPtr        CurrGrafPort;
  332.     SWORD            OldFont, OldSize, OldFace;
  333.     ColorSpec    OldFore, OldBack;
  334.     
  335.     if (PackDataHnd == NULL)
  336.         SysBeep(10);
  337.     ThePICT = GetPicture((*PackDataHnd)->DefCPICTResUp);
  338.     // Figure out where the default picture goes
  339.     if (ThePICT != NULL)
  340.     {
  341.         PICTRect = (*ThePICT)->picFrame;
  342.     }
  343.     else
  344.     {
  345.         PICTRect.top = PICTRect.bottom = PICTRect.left = PICTRect.right = 0;
  346.     }
  347.     OffsetRect(&PICTRect,-(PICTRect.right),-(PICTRect.top));
  348.     OffsetRect(&PICTRect,bounds->right,bounds->top);
  349.     TopBorder = (*PackDataHnd)->DefPixLead;
  350.     RightBorder = (*PackDataHnd)->DefPixGap + PICTRect.right - PICTRect.left;
  351.     GetPort(&CurrGrafPort);
  352.     OldFont = CurrGrafPort->txFont;
  353.     OldSize = CurrGrafPort->txSize;
  354.     OldFace = CurrGrafPort->txFace;
  355.     TextFont((*PackDataHnd)->DefTextFont);
  356.     TextSize((*PackDataHnd)->DefTextSize);
  357.     TextFace((Style)(Byte)(*PackDataHnd)->DefTextStyle);
  358.     GetFontInfo(&FntInfo);
  359.     
  360.     TextRect.top = bounds->top + TopBorder;
  361.     TextRect.left = bounds->left;
  362.     TextRect.bottom = TextRect.top + FntInfo.ascent + FntInfo.descent;
  363.     TextRect.right = bounds->right - RightBorder;
  364.     SectRect(&TextRect,bounds,&TextRect);
  365.     SaveFore(&OldFore);
  366.     SaveBack(&OldBack);
  367.     if (ThePICT != NULL) 
  368.         DrawPicture(ThePICT,&PICTRect);
  369.     PmForeColor((*PackDataHnd)->DefTextFGColor);
  370.     PmBackColor((*PackDataHnd)->DefTextBGColor);
  371.     EraseRect(&TextRect);
  372.     MoveTo(TextRect.left + 1,TextRect.top + FntInfo.ascent);
  373.     DrawString((ConstStr255Param)name);
  374.     RestoreFore(&OldFore);
  375.     RestoreBack(&OldBack);
  376.     TextFont(OldFont);
  377.     TextSize(OldSize);
  378.     //v1.1.1a2
  379.     // change the following line
  380.     //TextFace((Style)(Byte)OldSize);
  381.     // to:
  382.     TextFace((Style)(Byte)OldFace);
  383.     // for obvious reasons. <grimace>  This bug caused any text displayed after a
  384.     // ComboBox in the Design view to be drawn in the wrong place!
  385. }
  386.  
  387.  
  388. //---------------------------------------------------------------------------------
  389. //
  390. // FUNCTION: LaunchListProcess
  391. //
  392. //---------------------------------------------------------------------------------
  393.  
  394. void LaunchListProcess(PackHnd PackData)
  395. {
  396.     SBYTE    procName[13];
  397.     SLONG ListProcID; // v1.0.1  to fix unlocked PackData handle problem
  398.     OSErr    err;
  399.     
  400.     procName[0] = (SBYTE)12;
  401.     procName[1]  = '$';
  402.     procName[2]  = 'C';
  403.     procName[3]  = 'B';
  404.     procName[4]  = '_';
  405.     procName[5]  = 'L';
  406.     procName[6]  = 'i';
  407.     procName[7]  = 's';
  408.     procName[8]  = 't';
  409.     procName[9]  = 'P';
  410.     procName[10] = 'r';
  411.     procName[11] = 'o';
  412.     procName[12] = 'c';
  413.     
  414.     //v1.0.1 replaced following line:
  415.     //  err = LaunchProcess(ListProcess,'CBlp',kBaseResID,16000,procName,&((*PackData)->ListProcID));
  416.     //with:
  417.     err = LaunchProcess(ListProcess,'CBlp',kBaseResID,16000,procName,&ListProcID);
  418.     //and added:
  419.     (*PackData)->ListProcID = ListProcID;
  420.     //because PackData could get moved and the ListProcID would get lost.  When that happened,
  421.     //AreaShowList() in the main process could not kEX_UNFREEZE it, and no updating occurred.
  422. }
  423.  
  424. //---------------------------------------------------------------------------------
  425. //
  426. // FUNCTION: InitAreaData
  427. //
  428. //---------------------------------------------------------------------------------
  429.  
  430. OSErr InitAreaData(AreaHnd* AreaDataHndPtr,PackHnd PackDataHnd,
  431.                                      Rect* AreaRect, EventRecord* event)
  432. {
  433.     OSErr                        err;
  434.     AreaPtr                    AreaDataPtr;
  435.     
  436.     *AreaDataHndPtr = (AreaHnd)NewHandleClear(sizeof(AreaStr));
  437.     err = MemError();
  438.     
  439.     if (err == noErr)
  440.     {
  441.         //•Allocate and initialize any memory needed by members of area data block.
  442.         HLock((Handle) *AreaDataHndPtr);
  443.         AreaDataPtr = **AreaDataHndPtr;
  444.         
  445.         InitAreaDefaults(AreaDataPtr, PackDataHnd);
  446.     
  447.         AreaDataPtr->isWindow = (event->when == kIsExternalWindow);
  448.         AreaDataPtr->isPrinting = (event->message == kIsPrinting);
  449.         AreaDataPtr->MyLytType = (event->modifiers == kIsOutputLayout)?kOutput:kInput;
  450.         
  451.         err = InitAreaStructs(AreaDataPtr, AreaRect, PackDataHnd);
  452.         
  453.         HUnlock((Handle) *AreaDataHndPtr);
  454.  
  455.         if (err)
  456.         {
  457.             DeInitAreaData(*AreaDataHndPtr);
  458.             DisposeHandle((Handle) *AreaDataHndPtr);
  459.         }
  460.     }
  461.     
  462.     return err;
  463. }
  464.  
  465.  
  466. //---------------------------------------------------------------------------------
  467. //
  468. // FUNCTION: InitAreaDefaults
  469. //
  470. //---------------------------------------------------------------------------------
  471.  
  472. void InitAreaDefaults (AreaPtr AreaDataPtr, PackHnd PackDataHnd)
  473. {
  474.     PackPtr    PackDataPtr;
  475.  
  476.     HLock((Handle) PackDataHnd);
  477.     PackDataPtr = *PackDataHnd;
  478.  
  479.     AreaDataPtr->ActivateTick        = 0;
  480.     AreaDataPtr->CPICTResUp            = PackDataPtr->DefCPICTResUp;
  481.     AreaDataPtr->CPICTResDn            = PackDataPtr->DefCPICTResDn;
  482.     AreaDataPtr->CPICTResDis        = PackDataPtr->DefCPICTResDis;
  483.     AreaDataPtr->MPICTResUp            = PackDataPtr->DefMPICTResUp;
  484.     AreaDataPtr->MPICTResDn            = PackDataPtr->DefMPICTResDn;
  485.     AreaDataPtr->MPICTResDis        = PackDataPtr->DefMPICTResDis;
  486.     AreaDataPtr->TextFont             =    PackDataPtr->DefTextFont;
  487.     AreaDataPtr->TextSize                = PackDataPtr->DefTextSize;
  488.     AreaDataPtr->TextStyle             = PackDataPtr->DefTextStyle;
  489.     AreaDataPtr->TextFGColor        = PackDataPtr->DefTextFGColor;
  490.     AreaDataPtr->TextBGColor        = PackDataPtr->DefTextBGColor;
  491.     AreaDataPtr->ListFont                = PackDataPtr->DefListFont;
  492.     AreaDataPtr->ListSize                = PackDataPtr->DefListSize;
  493.     AreaDataPtr->ListStyle             = PackDataPtr->DefListStyle;
  494.     AreaDataPtr->ListFGColor        = PackDataPtr->DefListFGColor;
  495.     AreaDataPtr->ListBGColor        = PackDataPtr->DefListBGColor;
  496.     AreaDataPtr->ListRows                = PackDataPtr->DefListRows;
  497.     AreaDataPtr->ListPos                = 0;
  498.     AreaDataPtr->PixGap                    = PackDataPtr->DefPixGap;
  499.     AreaDataPtr->TopGap                    = PackDataPtr->DefTopGap;
  500.     AreaDataPtr->LeftGap                = PackDataPtr->DefLeftGap;
  501.     AreaDataPtr->RightGap                = PackDataPtr->DefRightGap;
  502.     AreaDataPtr->PixLead                = PackDataPtr->DefPixLead;
  503.     AreaDataPtr->Flags.CanFind    = PackDataPtr->DefFlags.CanFind;
  504.     AreaDataPtr->Flags.CanFill    = PackDataPtr->DefFlags.CanFill;
  505.     AreaDataPtr->Flags.CanList    = PackDataPtr->DefFlags.CanList;
  506.     AreaDataPtr->Flags.CanEdit    = PackDataPtr->DefFlags.CanEdit;
  507.     AreaDataPtr->Flags.ListOnActivate = PackDataPtr->DefFlags.ListOnActivate;
  508.     AreaDataPtr->Flags.ListOnKeystroke = PackDataPtr->DefFlags.ListOnKeystroke;
  509.     AreaDataPtr->Flags.Visible    = true;
  510.     AreaDataPtr->Flags.Active        = false;
  511.     AreaDataPtr->Flags.Modified    = false;
  512.     AreaDataPtr->Flags.Enabled    = true;
  513.     AreaDataPtr->Flags.Open            = false;
  514.     AreaDataPtr->SearchTextLength = 0;
  515.     AreaDataPtr->SearchTextSize    = 0;
  516.  
  517.     HUnlock((Handle) PackDataHnd);
  518. }
  519.  
  520.  
  521. //---------------------------------------------------------------------------------
  522. //
  523. // FUNCTION: InitAreaStructs
  524. //
  525. //---------------------------------------------------------------------------------
  526.  
  527. OSErr InitAreaStructs(AreaPtr AreaDataPtr, Rect* AreaRect, PackHnd PackDataHnd)
  528. {
  529.     OSErr                        err;
  530.     
  531.     GetPort(&(AreaDataPtr->AreaGrafPort));
  532.     AreaDataPtr->SearchTextHandle = (XHANDLE)NewHandle(0);
  533.     err = MemError();
  534.     
  535.     if (AreaDataPtr->SearchTextHandle)
  536.     {
  537.         BlockMove(AreaRect,&AreaDataPtr->AreaRect,sizeof(Rect));
  538.         InitAreaPICT(AreaDataPtr);
  539.         err = InitAreaText(AreaDataPtr);
  540.         
  541.         if (err == noErr)
  542.             err = InitAreaList(AreaDataPtr,PackDataHnd);
  543.         
  544.     }
  545.     
  546.     return err;
  547. }
  548.  
  549.  
  550. //---------------------------------------------------------------------------------
  551. //
  552. // FUNCTION: InitAreaPICT
  553. //
  554. //---------------------------------------------------------------------------------
  555.  
  556. void InitAreaPICT (AreaPtr AreaDataPtr)
  557. {
  558.     PicHandle    ThePICT;
  559.  
  560.     ThePICT = GetPicture(AreaDataPtr->CPICTResUp);
  561.     if (ThePICT != NULL)
  562.     {
  563.         AreaDataPtr->PICTRect = (*ThePICT)->picFrame;
  564.         OffsetRect(&AreaDataPtr->PICTRect,
  565.                                 -(AreaDataPtr->PICTRect.right),
  566.                                 -(AreaDataPtr->PICTRect.top));
  567.         OffsetRect(&AreaDataPtr->PICTRect,
  568.                                 AreaDataPtr->AreaRect.right,
  569.                                 AreaDataPtr->AreaRect.top);
  570.     }    
  571. }
  572.  
  573.  
  574. //---------------------------------------------------------------------------------
  575. //
  576. // FUNCTION: InitAreaText
  577. //
  578. //---------------------------------------------------------------------------------
  579.  
  580. OSErr InitAreaText(AreaPtr AreaDataPtr)
  581. {
  582.     Rect                        TextDestRect;
  583.  
  584.     CalcTextRect(AreaDataPtr);
  585.  
  586.     BlockMove((const void *)&(AreaDataPtr->TextRect),
  587.                         (void *)&(TextDestRect),
  588.                         (Size) sizeof(Rect));
  589.     AreaDataPtr->TextTEHnd = TENew(&TextDestRect, &(AreaDataPtr->TextRect));
  590.     if (AreaDataPtr->TextTEHnd)
  591.     {
  592.         HLock((Handle)(AreaDataPtr->TextTEHnd));
  593.         (*(AreaDataPtr->TextTEHnd))->crOnly = -1;
  594.         (*(AreaDataPtr->TextTEHnd))->txFont = AreaDataPtr->TextFont;
  595.         (*(AreaDataPtr->TextTEHnd))->txSize = AreaDataPtr->TextSize;
  596.         (*(AreaDataPtr->TextTEHnd))->txFace = AreaDataPtr->TextStyle;
  597.         HUnlock((Handle)(AreaDataPtr->TextTEHnd));
  598.     }
  599.     return MemError();
  600. }
  601.  
  602.  
  603. //---------------------------------------------------------------------------------
  604. //
  605. // FUNCTION: InitAreaList
  606. //
  607. //---------------------------------------------------------------------------------
  608.  
  609. OSErr InitAreaList (AreaPtr AreaDataPtr, PackHnd PackDataHnd)
  610. {
  611.     Rect                        ListViewRect, dataBounds;
  612.     Point                        cSize;
  613.     ParameterBlock    block;
  614.     GrafPtr        CurrGrafPort;
  615.     FontInfo    FntInfo;
  616.     SWORD            CurrFont,CurrSize,CurrFace;
  617.         
  618.     CalcListRect(AreaDataPtr);
  619.     // Make view rectangle for ListManager record
  620.     BlockMove (&AreaDataPtr->ListRect, &ListViewRect, sizeof(Rect));
  621.     ListViewRect.right -= kScrollBarWidth;
  622.     OffsetRect(&ListViewRect, -ListViewRect.left, -ListViewRect.top);
  623.     // Setup other info for LNew()
  624.     dataBounds.top = dataBounds.left = 0;
  625.     dataBounds.right = 1;
  626.     dataBounds.bottom = AreaDataPtr->ListRows;
  627.     cSize.v = ListViewRect.bottom / AreaDataPtr->ListRows;
  628.     cSize.h = ListViewRect.right;
  629.     // Wait until the list's window exists (if it doesn't already)
  630.     while (!(*PackDataHnd)->ListWindow)
  631.         CALL4D(kEX_YIELD_ABSOLUTE,&block);
  632.     // Ahhh... Now we can create our ListManager record
  633.     AreaDataPtr->ListHnd = LNew(&ListViewRect,&dataBounds,cSize,0,
  634.                                                             (*PackDataHnd)->ListWindow,true,false,false,true);
  635.     //OK, now, let's make sure the text starts in the right place.
  636.     GetPort(&CurrGrafPort);
  637.     CurrFont = CurrGrafPort->txFont;
  638.     CurrSize = CurrGrafPort->txSize;
  639.     CurrFace = CurrGrafPort->txFace;
  640.     TextFont(AreaDataPtr->ListFont);
  641.     TextSize(AreaDataPtr->ListSize);
  642.     TextFace(AreaDataPtr->ListStyle);
  643.     GetFontInfo(&FntInfo);
  644.     TextFont(CurrFont);
  645.     TextSize(CurrSize);
  646.     TextFace(CurrFace);
  647.     
  648.     (*(AreaDataPtr->ListHnd))->indent.h = 1;
  649.     (*(AreaDataPtr->ListHnd))->indent.v = FntInfo.ascent;
  650.     return noErr;
  651. }
  652.  
  653.  
  654. //---------------------------------------------------------------------------------
  655. //
  656. // FUNCTION: DeInitAreaData
  657. //
  658. //---------------------------------------------------------------------------------
  659.  
  660. void DeInitAreaData (AreaHnd AreaDataHnd)
  661. {
  662.     AreaPtr    AreaDataPtr;
  663.     
  664.     HLock((Handle)AreaDataHnd);
  665.     AreaDataPtr = *AreaDataHnd;
  666.     
  667.     if (AreaDataPtr->TextTEHnd)
  668.         TEDispose(AreaDataPtr->TextTEHnd);
  669.     if (AreaDataPtr->SearchTextHandle)
  670.         DisposeHandle((Handle)AreaDataPtr->SearchTextHandle);
  671.     if (AreaDataPtr->ListHnd)
  672.         LDispose(AreaDataPtr->ListHnd);
  673.         
  674.     HUnlock((Handle)AreaDataHnd);
  675. }
  676.  
  677.  
  678. //---------------------------------------------------------------------------------
  679. //
  680. // FUNCTION: GetPackDataHnd
  681. //
  682. //---------------------------------------------------------------------------------
  683.  
  684. PackHnd GetPackDataHnd(void)
  685. {
  686.     ParameterBlock    block;
  687.     PackHnd                    PackDataHnd;
  688.     ValuePtr                value;
  689.  
  690.     block.fName[0] = (SBYTE)11;
  691.     block.fName[1] = 'C';
  692.     block.fName[2] = 'B';
  693.     block.fName[3] = '_';
  694.     block.fName[4] = 'P';
  695.     block.fName[5] = 'a';
  696.     block.fName[6] = 'c';
  697.     block.fName[7] = 'k';
  698.     block.fName[8] = 'D';
  699.     block.fName[9] = 'a';
  700.     block.fName[10] = 't';
  701.     block.fName[11] = 'a';
  702.     block.fName[12] = '\0';
  703.     
  704.     value = (ValuePtr) NewPtr(sizeof(ValueBlock));
  705.     block.fH = (XHANDLE)value;
  706.     
  707.     CALL4D(kEX_GET_GLOBALVAR,&block);
  708.  
  709.     PackDataHnd = (PackHnd)(value->uValue.fLongint);
  710.     DisposePtr((Ptr) value);
  711.     
  712.     return PackDataHnd;
  713. }
  714.